
package com.hmsg.health.dao;

import com.hmsg.health.bean.domain.BannerDo;
import com.hmsg.health.bean.domain.TaskDo;
import com.hmsg.health.bean.domain.UserDo;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface BannerDao {
	
    @Select("select * from s_banner where id=#{id}")
    BannerDo findOne(@Param("id")Integer id);
    
    
    @Select("<script>" +
    	    "select * from  `s_banner` where 1=1 " +
    	    "    <if test='info.id != null'>" +
    	    "     and `id` = #{info.id} " +
    	    "    </if>" +
    	
    	    "    <if test='info.status != null'>" +
    	    "    and  `type` = #{info.type} " +
    	    "    </if>" +
    	 
    	    "</script>")
    List<BannerDo> select(@Param("info") BannerDo info);
    
    @Delete("delete from s_banner where id=#{userId}")
    int delete(Integer userId);
    
  
    @Insert("<script>" +
    "insert into `s_banner` " +
    "  <set>" +
    "    <if test='info.image != null'>" +
    "     `image` = #{info.image}, " +
    "    </if>" +
    "    <if test='info.status != null'>" +
    "      `status` = #{info.status}, " +
    "    </if>" +
    "    <if test='info.sort != null'>" +
    "      `sort` = #{info.sort}" +
    "    </if>" +
  
    "  </set>" +
    "</script>")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	int save(@Param("info") BannerDo info);


    @Update({"<script>",
		"UPDATE  s_banner",
		"<trim prefix='set' suffixOverrides=','>",
		
		"<if test='user.status!=null'>",
		"status= #{user.status},",
		"</if>",
		"<if test='user.sort!=null'>",
		"sort= #{user.sort},",
		"</if>",
		"<if test='user.image!=null'>",
		"image= #{user.image},",
		"</if>",
		"</trim>",
		"where id = #{user.id}",
		"</script>"})
 	Integer update(@Param("user") BannerDo user);

	@Select("select * from s_banner order by sort desc")
    List<BannerDo> findAll();


}